#!/bin/bash
# - group
# - test

. $LKP_SRC/lib/debug.sh
. $LKP_SRC/lib/upload.sh

cd "$BENCHMARK_ROOT/igt" || exit

exclude=$BENCHMARK_ROOT/igt/exclude
test_file=$BENCHMARK_ROOT/igt/$group

exclude_tests()
{
	local excluded_tests=$(cat "$exclude" | grep -v "#")
	local test
	for test in ${excluded_tests[@]}
	do
		sed -i "/$test/d" $test_file
	done
}

exclude_tests

denylist=$BENCHMARK_ROOT/igt/tests/intel-ci/blacklist.txt
cat $denylist | grep -v -e ^# -e ^$ > $(dirname $denylist)/denylist
denylist=$(dirname $denylist)/denylist

while read testcase
do
	if [[ $test ]]; then
		# get subtests from test
		subtests=$test
	else
		# "sort -u" is to rm duplicate subtest "interruptible"
		subtests=$(build/tests/$testcase --list-subtest | sort -u)
	fi
	for subtest in ${subtests[@]}
	do
		full_test_name=igt@$testcase@$subtest

		echo $subtest | grep -q -e suspend -e hibernate -e S3 && {
			# add "-e S3" to skip PM-related test
			# [  133.586866] PM: suspend entry (deep)
			echo "LKP SKIP $full_test_name"
			continue
		}

		echo $full_test_name | grep -q -E -f $denylist && {
			echo "LKP SKIP $full_test_name"
			continue
		}

		log_cmd build/tests/$testcase --run-subtest $subtest 2>&1

		# #define IGT_EXIT_ABORT 112
		# Exit status indicating a severe test/enviroment failure, any continued
		# testing past this point can yeild unexpected reasults and is not recommended
		[ $? -eq 112 ] && exit 112
	done
done < $test_file

exit 0
